package banking4;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:恋恋
 * Date:2022-09-27
 * Time:20:41
 */
public class CheckingAccount extends Account {
    double overdraftProtection;//透支保障


    public CheckingAccount(double balance) {
        super(balance);
    }

    public CheckingAccount(double balance, double overdraftProtection) {
        super(balance);
        this.overdraftProtection = overdraftProtection;
    }

    @Override
    public boolean withdraw(double amt) {
        //当前余额足够弥补取款amt,则正常进行
        if (balance >= amt) {
            balance =balance-amt;
            return true;
        } else {
            if (balance < amt && amt-balance < overdraftProtection) {
                overdraftProtection = overdraftProtection +(balance-amt);
                balance = 0;
                return true;
            } else {
                this.balance = balance;//整个交易失败，但余额未受影响
                return false;
            }
        }
    }
}
